package cn.edu.sjtu.se.dslab.project;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import cn.edu.sjtu.se.dslab.auth.User;

/**
 * 项目与用户的关联类（项目参与者）
 * 
 * @author sunke
 * 
 */
@Entity
@Table(name = "user_project")
public class UserProject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6038840788383614234L;
	private long id;
	private Project project;
	private User user;
	/**
	 * 是否可以管理这个项目，owner默认可以管理
	 */
	private boolean admin;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH})
	@JoinColumn(name = "project_id")
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	
	@ManyToOne(cascade = { CascadeType.REFRESH})
	@JoinColumn(name = "user_id")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "isAdmin", nullable = true)
	public boolean isAdmin() {
		return admin;
	}

	public void setAdmin(boolean admin) {
		this.admin = admin;
	}
	
}
